package com.itheima.server.controller;

import com.itheima.autoconfig.template.AipTemplate;
import com.itheima.domain.UserInfo;
import com.itheima.server.interceptor.UserHolder;
import com.itheima.server.service.UserInfoService;
import com.itheima.server.service.UserService;
import com.itheima.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;


    /**
     * 保存用户信息
     * @param userInfo
     * @param token
     * @return
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity<String> loginReginfo(@RequestBody UserInfo userInfo, @RequestHeader("Authorization") String token){
        //从token中获取userId
        Long id = UserHolder.getUserId();
        userInfo.setId(id);

        //保存
        userInfoService.save(userInfo);
        return ResponseEntity.ok("OK");
    }

    /**
     * 上传头像
     * @param headPhoto
     * @param token
     * @return
     */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity<String> head(MultipartFile headPhoto,@RequestHeader("Authorization") String token){
        Long id = UserHolder.getUserId();
        userInfoService.uploadHeadPho(headPhoto,id);
        return ResponseEntity.ok("OK");
    }





}
